#include"thread.h"
/*void delete(const char* path) {
    DIR* pdir = opendir(path);
    if (pdir == NULL) {
        perror("opendir");
        exit(1);
    }
    
    struct dirent* pdirent;
    while ((pdirent = readdir(pdir)) != NULL) {
        const char* name = pdirent->d_name;
        if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
            continue;

        char subpath[256];
        sprintf(subpath, "%s/%s", path, name);

        if (pdirent->d_type == DT_DIR) {
            delete(subpath);
        }
        else {
            if (unlink(subpath) == -1) {
                perror("unlink");
                exit(1);
            }
        }
    }

    if (closedir(pdir) == -1) {
        perror("closedir");
        exit(1);
    }

    if (rmdir(path) == -1) {
        perror("rmdir");
        exit(1);
    }
}*/

int rmDir(dirID_t* dirID, int netfd) {
  //  char buf[1024];
    train_t train;
    recv(netfd,&train.length,sizeof(int),MSG_WAITALL);
    recv(netfd,train.buf,train.length,MSG_WAITALL);
    printf("ret_buf = %s\n",train.buf);

    char strID[256];
    get_user_dir(strID,dirID);
     char tmp[2048];
    strcpy(tmp, dirID->pwdID);
    strcat(tmp,"/");
    strcat(tmp,strID);
    strcat(tmp,"/");
    char newBuf[256];
    removeHiddenCharacters(train.buf,newBuf);
    strcat(tmp,newBuf);

    if (rmdir(dirID->pwdID) == -1) {
            perror("rmdir");
            return 0;
            }
     else{
           return -1;
         }
   // sprintf(netfd, "%s/%s", dirID->pwdID, dirID->userID.pFornt->dirName);
    return 0;
}
  
